using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace TumblrPlugin
{
    public abstract class SerializerBase<T>
    {
        public static T Deserialize(XmlDocument xmlDocument)
        {
            var reader = new XmlNodeReader(xmlDocument.DocumentElement);
            var ser = new XmlSerializer(typeof(T));
            return (T)ser.Deserialize(reader);
        }

        public static string Serialize(T obj)
        {
            var serializer = new XmlSerializer(typeof(T));
            var sb = new StringBuilder();
            var writer = new StringWriter(sb);

            serializer.Serialize(writer, obj);
            return sb.ToString();
        }
    }
}